package com.example.ythhome.login.api;

import com.example.ythhome.login.entity.LoginMsg;
import com.example.ythhome.login.entity.RouteData;
import com.example.ythhome.login.entity.User;
import com.example.ythhome.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("api/mine")
public class MineContrall {

    @Autowired
    UserService userService;

    @GetMapping("/query/{userno}")
    @ResponseBody
    public LoginMsg mine(@PathVariable("userno") String userno){
        User user = userService.getByUserNo(userno);
        LoginMsg loginMsg = new LoginMsg();

            loginMsg.setSuccess(true);
            RouteData routeData = new RouteData();
            routeData.setAvatar("https://avatars.githubusercontent.com/u/44761321");
            routeData.setUsername(user.getUserName());
            routeData.setNickname(user.getNickName());
            routeData.setEmail(user.getEmail());
            routeData.setPhone(user.getPhone());
            routeData.setDescription(user.getIntroduction());
            routeData.setAccessToken("eyJhbGciOiJIUzUxMiJ9.admin");
            routeData.setRefreshToken("eyJhbGciOiJIUzUxMiJ9.adminRefresh");
            routeData.setExpires("2030/10/30 00:00:00");
//            User.UserBuilder users = User.withDefaultPasswordEncoder();
//            UserDetails user = users.username(accountName).password(accountPwd).roles("USER","ADMIN").build();
//             new InMemoryUserDetailsManager(user);
            loginMsg.setData(routeData);

        return loginMsg;
    };
}
